#include <stdio.h>
#include <arpa/inet.h>
#include <unistd.h>

int main(int count, char *arg[])
{
     struct sockaddr_in sin;
     sin.sin_family = AF_INET;//IPV4的网络地址版本
     sin.sin_port = htons(9999);//把9000号端口转为网络字节序并赋值给端口参数

     u_int32_t ip = 0;
     //把字符串ip地址转为网络字节序ip
     inet_pton(AF_INET,"192.168.50.143",&ip);
     sin.sin_addr.s_addr = ip;

     //创建一个tcp套接字，参数1指定地址族，参数2指定协议，SOCK_STREAM代表是TCP，SOCK_DGRAM代表UDP
     int sID = socket(AF_INET,SOCK_STREAM,0);

     while(-1 == connect(sID,(struct sockaddr*)&sin,sizeof(struct sockaddr_in)))
     {
          perror("连接服务器中...");
          sleep(1);
     }

     char buf[128];
     read(sID,buf,sizeof(buf));
     printf("收到服务器发来的数据：%s\n",buf);

     close(sID);

     return 0;
}